﻿package src.uipackage.ui.graphics {
	
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.text.AntiAliasType;
	import flash.text.Font;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	/**
	* Creates option buttons for OBO_ComboBox class.
	* @author Devon O.
	*/
	
	public class ComboOption extends SimpleButton {
		
		private var _fontLabel:TextField;
		private var _size:int;
		private var _width:int;
		private var _label:String;
		private var _data:*;
		private var _boxHeight:Number;
		
		public function get label():String {
			return _label;
		}
		public function get data():* {
			return _data;
		}
		
		public function ComboOption(label:String, data:*, width:int, fontsize:int = 11):void {
			_label = label;
			_data = data;
			_size = fontsize;
			_width = width;
			_fontLabel = addLabel();
			_boxHeight = _fontLabel.height;
			upState = upSprite();
			overState = overSprite();
			downState = upSprite();
			hitTestState = upSprite();
		}
		private function upSprite():Sprite {
			var s:Sprite = new Sprite();
			s.graphics.beginFill(0xEFEFEF);
			s.graphics.drawRect(0, 0, _width, _boxHeight);
			s.graphics.endFill();
			s.addChild(addLabel());
			return s;
		}
		private function overSprite():Sprite {
			var s:Sprite = new Sprite();
			s.graphics.beginFill(0xDFDFDF);
			s.graphics.drawRect(0, 0, _width, _boxHeight);
			s.graphics.endFill();
			s.addChild(addLabel());
			return s;
		}

		private function addLabel():TextField {
			var tf:TextField = new TextField();
			tf.antiAliasType = AntiAliasType.ADVANCED;
			var fmt:TextFormat = (_data is Font) ? new TextFormat(_data.fontName, _size) : new TextFormat("_sans", _size);
			tf.defaultTextFormat = fmt;
			tf.embedFonts = (_data is Font);
			tf.selectable = false;
			tf.mouseEnabled = false;
			
			tf.text = _label;
			tf.width = _width - 2;
			tf.height = tf.textHeight + 4;
			return tf;
		}
	}
}